package com.luhui.yyb;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author:Luhui
 * @qq:729913162
 * @Date:2018/10/30 0030
 * @Time:21:47
 */
public class Util {
    public static String getHTML(String inputUrl,String cookie,String charset){
        URL url;
        try {
            url = new URL(inputUrl);
            URLConnection urlConn = url.openConnection();
            urlConn.setRequestProperty("content-type","text/html;charset=utf-8");
            urlConn.setRequestProperty("Cookie",cookie);
            BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream(),charset));
            StringBuffer context = new StringBuffer();
            String str = null;
            while((str=br.readLine())!=null){
                context.append(str+"\n");
            }
            return context.toString();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        return null;

    }
}
